home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / widgets / scrltxed.sx < prev    next >
Encoding:
Text File  |  1995-12-13  |  3.7 KB  |  137 lines  |  [TEXT/ttxt]

  1. class ScrollingTextEdit(ScrollingPresenter)
  2. instance vars
  3.     autoRecalc
  4.     frame,
  5.     _font
  6. end
  7.  
  8. method init self {class ScrollingTextEdit}  #rest args    #key\
  9.             text:myText("")                            \
  10.             vertScrollBarDisplayed:(@always)        \
  11.             boundary:                                \
  12.             textWidth:                                \
  13.             textHeight:(300)                        \
  14.             autoRecalc:(true)                        \
  15.             ->
  16. (
  17.     self.autoRecalc := autoRecalc
  18.     self.frame := new Frame -- place here so that layout() is called properly
  19.     local vScroll := new SimpleScrollBar orientation:@vertical height:boundary.height
  20.     vScroll.directDrag := true
  21.     apply NextMethod self fill:WhiteBrush boundary:boundary \
  22.         vertScrollBar:vScroll stationary:true args
  23.     
  24.     if (textWidth = unsupplied) do
  25.         textWidth := self.clippingPresenter.width
  26.     if (autoRecalc) do textHeight := boundary.height
  27.     local textBounds := new Rect x2:textWidth y2:textHeight
  28.     local target := new Text String:myText
  29.     local te := new TextEdit target:target boundary:textBounds
  30.     self.targetPresenter := te
  31. )
  32.  
  33. method afterInit self {class ScrollingTextEdit} #rest args #key\
  34.     font:(theAppFont) ->
  35. (
  36.     apply NextMethod self args
  37.     self.font := font
  38.     self.targetPresenter.inset := new Point x:3 y:0
  39.     self.targetPresenter.selectionBackground := whiteBrush
  40. )
  41.  
  42. method recalcHeight self {class ScrollingTextEdit} -> (
  43.     if (not self.autoRecalc) do return
  44.     local tp := self.targetPresenter
  45.     local fnt := self.font
  46.     
  47.     tp.height := (calculate tp @width tp.width) + fnt.fontSize + fnt.leading + fnt.descent
  48.     layout self
  49. )
  50.  
  51. method fontGetter self {class ScrollingTextEdit} -> self._font
  52. method fontSetter self {class ScrollingTextEdit} newFont ->
  53. (
  54.     self._font := newFont
  55.     local textP := self.targetPresenter
  56.     setDefaultAttr textP @font newFont.font
  57.     setDefaultAttr textP @leading newFont.leading
  58.     setDefaultAttr textP @size newFont.fontSize
  59.     if (self.presentedBy !== undefined) do
  60.         recalcHeight self
  61.     textP.cursor := new Rect x1:-1 x2:0 \
  62.         y1:(-newFont.leading + newFont.descent) y2:0
  63.     local vScroll := self.vertScrollBar
  64.     if (vScroll != undefined) do
  65.         vScroll.stepAmount := newFont.leading
  66.     newFont
  67. )
  68.  
  69. method widthSetter self {class ScrollingTextEdit} val ->
  70. (
  71.     local tp := self.targetPresenter
  72.     
  73.     nextMethod self val
  74.     tp.width := self.clippingPresenter.width
  75.     if (self.presentedBy !== undefined) do
  76.         recalcHeight self
  77.     val
  78. )
  79.  
  80. method recalcRegion self {class ScrollingTextEdit} ->
  81. (
  82.     NextMethod self
  83.     if (self.frame <> undefined) do
  84.         SetBoundary self.frame self.boundary
  85.     local vScroll := self.vertScrollBar
  86.     if (vScroll != undefined) do
  87.         vScroll.pageAmount := self.clippingPresenter.height - self.font.leading
  88. )
  89.  
  90. method draw self {class ScrollingTextEdit} surface clip ->
  91. (
  92.     NextMethod self surface clip
  93.     if (self.frame != undefined) do
  94.         drawLoweredFrame self.frame surface clip self.globalTransform
  95. )
  96.  
  97. method layout self {class ScrollingTextEdit} ->
  98. (
  99.     local compositor := self.compositor
  100.     if (compositor != undefined) do ignoreRefreshRegion compositor true
  101.     NextMethod self
  102.     if (self.frame != undefined) do (
  103.         local clipP := self.clippingPresenter
  104.         clipP.x := clipP.y := 2
  105.         clipP.width := clipP.width - 4
  106.         clipP.height := clipP.height - 4
  107.         local vScroll := self.vertScrollBar
  108.         if (vScroll != undefined) do (
  109.             vScroll.x := vScroll.x - 1
  110.             vScroll.y := 1
  111.             vScroll.height := vScroll.height - 2
  112.         )
  113.         local hScroll := self.horizScrollBar
  114.         if (hScroll != undefined) do (
  115.             hScroll.x := 1
  116.             hScroll.y := hScroll.y - 1
  117.             hScroll.width := hScroll.width - 2
  118.         )
  119.     )
  120.     if (compositor != undefined) do ignoreRefreshRegion compositor false
  121.     NotifyChanged self true
  122. )
  123.  
  124. method textGetter self {class ScrollingTextEdit} ->
  125. (
  126.     self.targetPresenter.target
  127. )
  128.  
  129. method textSetter self {class ScrollingTextEdit} newText ->
  130. (
  131.     local tp := self.targetPresenter
  132.     
  133.     tp.target := newText as Text
  134.     if (self.presentedBy !== undefined) do
  135.         recalcHeight self
  136. )
  137.